package net.htjs.juc.thread;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

@Slf4j
public class ThreadJoin {

    static int r = 0;

    public static void main(String[] args) {
        test();
    }

    private static void test() {
        log.info("开始");
        Thread thread1 = new Thread(() -> {
            log.info("开始");
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            log.info("结束");
            r = 10;
        }, "Thread-1");
        try {
            thread1.start();
            //等待线程结束后在运行主线程
            thread1.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        log.info("结果为:{}", r);
        log.info("结束");
    }


}
